import sys
import os
import configparser

def cfg_del():
    configPath = os.path.join(os.getcwd(), "opt.ini")
    print("INI File is" + configPath)
    conf = configparser.ConfigParser()
    # 读取.ini文件
    conf.read(configPath)
    port = conf.get("COM","FLASH_PORT")
    baud = conf.get("COM","FLASH_BAUD")
    prjname = conf.get("PRJ","ELFNAME")
    print(port)

    #run
    os.chdir('build')
    os.system("python $IDF_PATH/components/esptool_py/esptool/esptool.py " + "-p /dev/" + port + " -b " + baud + " --chip esp32 write_flash @flash_project_args")
    os.system("python $IDF_PATH/tools/idf_monitor.py -p /dev/" + port + " " + prjname + ".elf")

cfg_del()




